home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
systray
/
systray.frm
< prev
next >
Wrap
Text File
|
1999-10-10
|
3KB
|
99 lines
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Systray"
ClientHeight = 495
ClientLeft = 165
ClientTop = 1515
ClientWidth = 1560
Icon = "systray.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 495
ScaleWidth = 1560
Begin VB.CommandButton Command1
Caption = "Minimize to Systray"
Height = 495
Left = 0
TabIndex = 0
Top = 0
Width = 1560
End
Begin VB.Menu mPopupSys
Caption = "&SysTray"
Visible = 0 'False
Begin VB.Menu mPopRestore
Caption = "&Restore"
End
Begin VB.Menu mPopExit
Caption = "&Exit"
End
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Form1.WindowState = vbMinimized
Shell_NotifyIcon NIM_ADD, nid 'Adds the cion to the SysTray
End Sub
Private Sub Form_Load()
Me.Show 'Makes sure the form is shown
With nid
.cbSize = Len(nid)
.hwnd = Me.hwnd
.uID = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon 'Sets the icon to show in the SysTray
.szTip = "Your ToolTip" & vbNullChar 'change the Your ToolTip to what you want to show up as the tool tip for the icon in the SysTray
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim Result As Long, msg As Long 'Dims Result and msg as long for later use
If Me.WindowState = 1 Then 'checks if the form is in the SysTray
msg = x 'makes msg the x position of the mouse
Select Case msg 'starts select block to see what the msg from the systray returns
Case WM_LBUTTONUP 'check to see if the left mouse button was released
Me.WindowState = vbNormal 'restores the form to normal state
Result = SetForegroundWindow(Me.hwnd) 'Sets the form as a foreground window
Me.Show 'Makes sure the form is shown
Case WM_LBUTTONDBLCLK 'Checks to see if the left mouse button was double clicked
Me.WindowState = vbNormal 'restores the form to normal state
Result = SetForegroundWindow(Me.hwnd) 'Sets the form as a foreground window
Me.Show 'Makes sure the form is shown
Case WM_RBUTTONUP 'Checks to see if the right mouse button was released
Result = SetForegroundWindow(Me.hwnd) 'Sets the form as a foreground window
Me.PopupMenu Me.mPopupSys 'Pops up the menu when the right mouse button is released
End Select 'Ends select block
Else 'If the form isn't in the SysTray then
msg = x / Screen.TwipsPerPixelX 'makes msg the position of the mouse divided by the sereen's twips per pixel on the x axies
End If
End Sub
Private Sub Form_Resize()
If Me.WindowState = vbMinimized Then Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, nid
End Sub
Private Sub mPopExit_Click()
Shell_NotifyIcon NIM_DELETE, nid
Unload Me
End
End Sub
Private Sub mPopRestore_Click()
Me.WindowState = vbNormal
Result = SetForegroundWindow(Me.hwnd)
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
End Sub